
#include"star.h"
#pragma once

int find();
void Event::EventFun(int x)
{
    //int event_time;//记录事件生效时间 1：立即生效 2：回合开始时生效
    //int event_id;//记录事件编号
    //std::string event_name;//记录事件名
    srand((unsigned)time(NULL));
    switch (event_id)
    {
    case 1: {this->event_name = "前有滚石"; this->event_time = 2;
        while (now_round % 4 == 0)
        {
            this->event_time = 1;
            //每四回合触发一次，将一条直线上的角色推到拐角处
            if (player[x].mp_locat == 12 || player[x].mp_locat == 18 ||
                player[x].mp_locat == 86)//玩家位置
            {
                for (int i = 1; i <= 9; i++)
                {

                    while (player[i].mp_locat == 13 || player[i].mp_locat == 29 ||
                        player[i].mp_locat == 30 || player[i].mp_locat == 36 ||
                        player[i].mp_locat == 37 || player[i].mp_locat == 28)
                    {
                        player[i].mp_locat = 28;
                    }

                    while (player[i].mp_locat == 11 || player[i].mp_locat == 10 ||
                        player[i].mp_locat == 9 || player[i].mp_locat == 8 ||
                        player[i].mp_locat == 7 || player[i].mp_locat == 6)
                    {
                        player[i].mp_locat = 6;
                    }

                }
            }
        }}
          break;
    case 2: {event_name = "挖宝地点"; event_time = 1;
        //每个路过挖宝地点的人可以获得一次三选一道具的机会,直接到达随机地点。
        if (player[x].mp_locat == 34 || player[x].mp_locat == 33 ||
            player[x].mp_locat == 23 || player[x].mp_locat == 41 ||
            player[x].mp_locat == 2 || player[x].mp_locat == 3 ||
            player[x].mp_locat == 4 || player[x].mp_locat == 5 ||
            player[x].mp_locat == 67 || player[x].mp_locat == 54 ||
            player[x].mp_locat == 50
            ) //(玩家位置 = 该事件位置)
        {

            // mp_local= (rand() % 88);
             //三选一道具
            int j = 0;
           
            for (int i = 0; i < 3; i++)
            {
               j = rand() % 7;
               // Loot* p[10];
                //Loot* e = player[x].event_queue[j];
            } 
            Loot* e = player[x].loot_queue[j];
            //ChooseLoot(j);//选择道具
            player[x].mp_locat = (rand() % 88);
        }
    }
          break;
    
    case 4: {event_name = "牢底坐穿"; event_time = 1;
        //停止行动一回合
        for (int i = 1; i <= 9; i++)
        {
            if (player[x].mp_locat == 9 || player[x].mp_locat == 16
                || player[x].mp_locat == 20 || player[x].mp_locat == 32 ||
                player[x].mp_locat == 37 || player[x].mp_locat == 42 ||
                player[x].mp_locat == 27)//玩家位置
            {


            }
        }}
          break;
    case 5: {
        event_name = "路过起点"; event_time = 1;

        //该玩家的星星加1      
        if (player[x].mp_locat == 0)
        {
            player[x].star_num += 1;
        }
    }
          break;
    case 6: {
        event_name = "十字岔口"; event_time = 1;
        //随着回合数不断改变行走方向
        if (player[x].mp_locat == 13 || player[x].mp_locat == 24 ||
            player[x].mp_locat == 25 || player[x].mp_locat == 26 ||
            player[x].mp_locat == 47 || player[x].mp_locat == 63 ||
            player[x].mp_locat == 72 || player[x].mp_locat == 69)
        {
            //交换下一格的编号
            mp[x]->nex_id1 = mp[x]->nex_id2;

        }}
          break;
    case 7: {event_name = "传送门"; event_time = 1;
        //直接传送到星星前一格
        if (player[x].mp_locat == 22 || player[x].mp_locat == 30 ||
            player[x].mp_locat == 57 || player[x].mp_locat == 85)
        {
            
            //玩家位置调到星星坐标的前一格子
            player[x].mp_locat = find();
           
        }
    }

          break;
    case 8: {event_name = "流星雨"; event_time = 1;
        //在游戏进行到剩余2回合时，地图上随机刷出5个额外的星星

        if (player[x].mp_locat == 28 || player[x].mp_locat == 51 ||
            player[x].mp_locat == 56 || player[x].mp_locat == 83)
        {
            if (20 - now_round == 2)
            {
                //输出5个额外的星星
                for (int i = 0; i < 5; i++)
                {
                    CreatStar();
                }

            }
        }
    }

          break;
    default:"error";
        break;

    }

}
bool Event::Check(int x)
{
    if (x == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int find()
{
    int a=0;
    for (int i = 0; i < 88; i++)
    {
        if (mp[i]->star == 1)
        {
            a = i;
            break;
        }
    }
    return a - 1;
}

